import { has } from "lodash";

/**
 * @see https://umijs.org/docs/max/access#access
 * */
export default function access(initialState: { currentUser?: API.CurrentUser } | undefined) {
  const { currentUser } = initialState ?? {};
  return {
    canAdmin: currentUser && currentUser.access === 'admin',
    hasRoute: (route) => {
      let canmenu = JSON.parse(localStorage.getItem('canmenu'));
      return canmenu.includes(route.name);
    }
  };
}
